define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {

    var Controller = {
        index: function() {
            const today = new Date(); // 今天日期
            const sevenDaysAgo = new Date();
            sevenDaysAgo.setDate(today.getDate() - 7);
            new Vue({
                el: '#app',
                data: {
                    message: 'Hello Vue2!',
                    option: {
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [{
                            data: [820, 932, 901, 934, 1290, 1330, 1320],
                            type: 'line',
                            areaStyle: {}
                        }]
                    },

                    option2: {
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [{
                            data: [820, 932, 901, 934, 1290, 1330, 1320],
                            type: 'line',
                            areaStyle: {}
                        }]
                    },

                    lineChart1: {},
                    lineChart2: {},
                    time1: [sevenDaysAgo, today], // 默认选中 [今天, 今天]
                    time2: [sevenDaysAgo, today], // 默认选中 [今天, 今天]
                    pickerOptions: {
                        shortcuts: [{
                            text: '昨天',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '今天',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '上个月',
                            onClick(picker) {
                                const now = new Date();

                                // 当前月的第一天
                                const thisMonthFirst = new Date(now.getFullYear(), now.getMonth(), 1);
                                // 上个月的第一天
                                const lastMonthFirst = new Date(now.getFullYear(), now.getMonth() - 1, 1);
                                // 上个月的最后一天 = 当前月第一天 - 1天
                                const lastMonthLast = new Date(thisMonthFirst.getTime() - 24 * 60 * 60 * 1000);

                                picker.$emit('pick', [lastMonthFirst, lastMonthLast]);
                            }
                        }, {
                            text: '最近一周',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '最近一个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '最近三个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                picker.$emit('pick', [start, end]);
                            }
                        }]
                    },
                    s_day: sevenDaysAgo,
                    e_day: today
                },
                created() {

                    var that = this

                    setTimeout(function() {
                        that.s_day = that.formatDate(that.s_day)
                        that.e_day = that.formatDate(that.e_day)
                        that.show_line1()
                        that.show_line2()
                        that.show_line3()
                        that.show_line4()
                    }, 1000);



                },
                methods: {
                    formatDate(date) {
                        const y = date.getFullYear()
                        const m = String(date.getMonth() + 1).padStart(2, '0')
                        const d = String(date.getDate()).padStart(2, '0')
                        return `${y}-${m}-${d}`
                    },
                    getData(e) {
                        this.s_day = this.formatDate(e[0])
                        this.e_day = this.formatDate(e[1])
                        this.show_line1()
                        this.show_line2()
                        this.show_line3()
                        this.show_line4()
                    },
                    show_line1() {
                        Fast.api.ajax({
                            url: 'dashboard/getOrderData',
                            type: 'GET',
                            data: {
                                start: this.s_day,
                                endStr: this.e_day,
                            }
                        }, function(ret, res) {

                            if (res.code == 1) {
                                var myChart = Echarts.init(document.getElementById('line-chart1'), 'walden');

                                // 指定图表的配置项和数据
                                var option = {
                                    tooltip: {
                                        trigger: 'axis',

                                    },
                                    legend: {
                                        top: '2%',
                                        left: 'center'
                                    },
                                    xAxis: {
                                        type: 'category',
                                        data: res.data.xAxis
                                    },
                                    yAxis: {
                                        type: 'value'
                                    },
                                    series: res.data.series
                                };
                                // 使用刚指定的配置项和数据显示图表。
                                myChart.setOption(option);
                                window.addEventListener('resize', () => {
                                    myChart.resize(); // 用箭头函数包装
                                });
                            }
                            return false
                        }, function(ret, res) {})
                    },

                    show_line2() {
                        Fast.api.ajax({
                            url: 'dashboard/getOrderOrderItemTop',
                            type: 'GET',
                            data: {
                                start: this.s_day,
                                endStr: this.e_day,
                            }
                        }, function(ret, res) {

                            if (res.code == 1) {
                                var myChart = Echarts.init(document.getElementById('line-chart2'), 'walden');

                                // 指定图表的配置项和数据
                                var option = {
                                    tooltip: {
                                        trigger: 'axis',

                                    },
                                    legend: {
                                        top: '2%',
                                        left: 'center'
                                    },
                                    xAxis: {
                                        type: 'category',
                                        data: res.data.xAxis
                                    },
                                    yAxis: {
                                        type: 'value'
                                    },
                                    series: res.data.series
                                };
                                // 使用刚指定的配置项和数据显示图表。
                                myChart.setOption(option);
                                window.addEventListener('resize', () => {
                                    myChart.resize(); // 用箭头函数包装
                                });
                            }
                            return false
                        }, function(ret, res) {})
                    },
                    show_line3() {
                        Fast.api.ajax({
                            url: 'dashboard/getOrderUserTop',
                            type: 'GET',
                            data: {
                                start: this.s_day,
                                endStr: this.e_day,
                            }
                        }, function(ret, res) {

                            if (res.code == 1) {
                                var myChart = Echarts.init(document.getElementById('line-chart3'), 'walden');

                                // 指定图表的配置项和数据
                                var option = {
                                    tooltip: {
                                        trigger: 'axis',

                                    },
                                    legend: {
                                        top: '2%',
                                        left: 'center'
                                    },
                                    xAxis: {
                                        type: 'category',
                                        data: res.data.xAxis
                                    },
                                    yAxis: {
                                        type: 'value'
                                    },
                                    series: res.data.series
                                };
                                // 使用刚指定的配置项和数据显示图表。
                                myChart.setOption(option);
                                window.addEventListener('resize', () => {
                                    myChart.resize(); // 用箭头函数包装
                                });
                            }
                            return false
                        }, function(ret, res) {})
                    },
                    show_line4() {
                        Fast.api.ajax({
                            url: 'dashboard/getOrderFenleiTop',
                            type: 'GET',
                            data: {
                                start: this.s_day,
                                endStr: this.e_day,
                            }
                        }, function(ret, res) {

                            if (res.code == 1) {
                                var myChart = Echarts.init(document.getElementById('line-chart4'), 'walden');

                                // 指定图表的配置项和数据
                                var option = {
                                    tooltip: {
                                        trigger: 'axis',

                                    },
                                    legend: {
                                        top: '2%',
                                        left: 'center'
                                    },
                                    xAxis: {
                                        type: 'category',
                                        data: res.data.xAxis
                                    },
                                    yAxis: {
                                        type: 'value'
                                    },
                                    series: res.data.series
                                };
                                // 使用刚指定的配置项和数据显示图表。
                                myChart.setOption(option);
                                window.addEventListener('resize', () => {
                                    myChart.resize(); // 用箭头函数包装
                                });
                            }
                            return false
                        }, function(ret, res) {})
                    },
                    changeMessage() {

                    }
                }
            });




        },
        index2: function() {
            const today = new Date(); // 今天日期
            const sevenDaysAgo = new Date();
            sevenDaysAgo.setDate(today.getDate() - 7);
            new Vue({
                el: '#app',
                data: {
                    message: 'Hello Vue2!',
                    option: {
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [{
                            data: [820, 932, 901, 934, 1290, 1330, 1320],
                            type: 'line',
                            areaStyle: {}
                        }]
                    },

                    option2: {
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [{
                            data: [820, 932, 901, 934, 1290, 1330, 1320],
                            type: 'line',
                            areaStyle: {}
                        }]
                    },

                    lineChart1: {},
                    lineChart2: {},
                    time1: [sevenDaysAgo, today], // 默认选中 [今天, 今天]
                    time2: [sevenDaysAgo, today], // 默认选中 [今天, 今天]
                    pickerOptions: {
                        shortcuts: [{
                            text: '昨天',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '今天',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '上个月',
                            onClick(picker) {
                                const now = new Date();

                                // 当前月的第一天
                                const thisMonthFirst = new Date(now.getFullYear(), now.getMonth(), 1);
                                // 上个月的第一天
                                const lastMonthFirst = new Date(now.getFullYear(), now.getMonth() - 1, 1);
                                // 上个月的最后一天 = 当前月第一天 - 1天
                                const lastMonthLast = new Date(thisMonthFirst.getTime() - 24 * 60 * 60 * 1000);

                                picker.$emit('pick', [lastMonthFirst, lastMonthLast]);
                            }
                        }, {
                            text: '最近一周',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '最近一个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '最近三个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                picker.$emit('pick', [start, end]);
                            }
                        }]
                    },
                    s_day: sevenDaysAgo,
                    e_day: today
                },
                created() {

                    var that = this

                    setTimeout(function() {
                        that.s_day = that.formatDate(that.s_day)
                        that.e_day = that.formatDate(that.e_day)
                        that.show_line0()
                        that.show_line1()
                        that.show_line2()
                        that.show_line3()
                        that.show_line4()
                    }, 1000);



                },
                methods: {
                    formatDate(date) {
                        const y = date.getFullYear()
                        const m = String(date.getMonth() + 1).padStart(2, '0')
                        const d = String(date.getDate()).padStart(2, '0')
                        return `${y}-${m}-${d}`
                    },
                    getData(e) {
                        this.s_day = this.formatDate(e[0])
                        this.e_day = this.formatDate(e[1])
                        this.show_line0()
                        this.show_line1()
                        this.show_line2()
                        this.show_line3()
                        this.show_line4()
                    },
                    show_line0(item) {



                        Fast.api.ajax({
                            url: 'dashboard/getOrderLirun',
                            type: 'GET',
                            data: {
                                start: this.s_day,
                                endStr: this.e_day,
                            }
                        }, function(ret, res) {

                            if (res.code == 1) {
                                 var myChart = Echarts.init(document.getElementById('line-chart0'), 'walden');
                                // 指定图表的配置项和数据
                                var option = {

                                    tooltip: {
                                        trigger: 'item',
                                        formatter: '{b}<br/>金额: {c} 元<br/>占比: {d}%'
                                    },
                                    legend: {
                                        top: '2%',
                                        left: 'center'
                                    },

                                    series: [{
                                        name: '详细信息',
                                        type: 'pie',
                                        center: ['50%', '60%'], // 默认是50%高度，往下移到60%
                                        label: {
                                            show: true, // 开启标签
                                            position: 'outside', // 默认外侧
                                            formatter: '{b}\n{c}', // 显示名称 + 数值
                                            fontSize: 14
                                        },
                                        data: res.data.series,
                                        emphasis: {
                                            itemStyle: {
                                                shadowBlur: 10,
                                                shadowOffsetX: 0,
                                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                                            }
                                        }
                                    }]
                                };

                                // 使用刚指定的配置项和数据显示图表。
                                myChart.setOption(option);
                                window.addEventListener('resize', () => {
                                    myChart.resize(); // 用箭头函数包装
                                });
                            }
                            return false
                        }, function(ret, res) {})




                    },
                    show_line1() {
                        Fast.api.ajax({
                            url: 'dashboard/getOrderDatalirun',
                            type: 'GET',
                            data: {
                                start: this.s_day,
                                endStr: this.e_day,
                            }
                        }, function(ret, res) {

                            if (res.code == 1) {
                                var myChart = Echarts.init(document.getElementById('line-chart1'), 'walden');

                                // 指定图表的配置项和数据
                                var option = {
                                    tooltip: {
                                        trigger: 'axis',

                                    },
                                    legend: {
                                        top: '2%',
                                        left: 'center'
                                    },
                                    xAxis: {
                                        type: 'category',
                                        data: res.data.xAxis
                                    },
                                    yAxis: {
                                        type: 'value'
                                    },
                                    series: res.data.series
                                };
                                // 使用刚指定的配置项和数据显示图表。
                                myChart.setOption(option);
                                window.addEventListener('resize', () => {
                                    myChart.resize(); // 用箭头函数包装
                                });
                            }
                            return false
                        }, function(ret, res) {})
                    },

                    show_line2() {
                        Fast.api.ajax({
                            url: 'dashboard/getOrderOrderItemToplirun',
                            type: 'GET',
                            data: {
                                start: this.s_day,
                                endStr: this.e_day,
                            }
                        }, function(ret, res) {

                            if (res.code == 1) {
                                var myChart = Echarts.init(document.getElementById('line-chart2'), 'walden');

                                // 指定图表的配置项和数据
                                var option = {
                                    tooltip: {
                                        trigger: 'axis',

                                    },
                                    legend: {
                                        top: '2%',
                                        left: 'center'
                                    },
                                    xAxis: {
                                        type: 'category',
                                        data: res.data.xAxis
                                    },
                                    yAxis: {
                                        type: 'value'
                                    },
                                    series: res.data.series
                                };
                                // 使用刚指定的配置项和数据显示图表。
                                myChart.setOption(option);
                                window.addEventListener('resize', () => {
                                    myChart.resize(); // 用箭头函数包装
                                });
                            }
                            return false
                        }, function(ret, res) {})
                    },
                    show_line3() {
                        Fast.api.ajax({
                            url: 'dashboard/getOrderUserToplirun',
                            type: 'GET',
                            data: {
                                start: this.s_day,
                                endStr: this.e_day,
                            }
                        }, function(ret, res) {

                            if (res.code == 1) {
                                var myChart = Echarts.init(document.getElementById('line-chart3'), 'walden');

                                // 指定图表的配置项和数据
                                var option = {
                                    tooltip: {
                                        trigger: 'axis',

                                    },
                                    legend: {
                                        top: '2%',
                                        left: 'center'
                                    },
                                    xAxis: {
                                        type: 'category',
                                        data: res.data.xAxis
                                    },
                                    yAxis: {
                                        type: 'value'
                                    },
                                    series: res.data.series
                                };
                                // 使用刚指定的配置项和数据显示图表。
                                myChart.setOption(option);
                                window.addEventListener('resize', () => {
                                    myChart.resize(); // 用箭头函数包装
                                });
                            }
                            return false
                        }, function(ret, res) {})
                    },
                    show_line4() {
                        Fast.api.ajax({
                            url: 'dashboard/getOrderFenleiToplirun',
                            type: 'GET',
                            data: {
                                start: this.s_day,
                                endStr: this.e_day,
                            }
                        }, function(ret, res) {

                            if (res.code == 1) {
                                var myChart = Echarts.init(document.getElementById('line-chart4'), 'walden');

                                // 指定图表的配置项和数据
                                var option = {
                                    tooltip: {
                                        trigger: 'axis',

                                    },
                                    legend: {
                                        top: '2%',
                                        left: 'center'
                                    },
                                    xAxis: {
                                        type: 'category',
                                        data: res.data.xAxis
                                    },
                                    yAxis: {
                                        type: 'value'
                                    },
                                    series: res.data.series
                                };
                                // 使用刚指定的配置项和数据显示图表。
                                myChart.setOption(option);
                                window.addEventListener('resize', () => {
                                    myChart.resize(); // 用箭头函数包装
                                });
                            }
                            return false
                        }, function(ret, res) {})
                    },
                    changeMessage() {

                    }
                }
            });




        },
        index3: function() {
            const today = new Date(); // 今天日期
            new Vue({
                el: '#app',
                data: {
                    message: 'Hello Vue2!',
                    option: {
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [{
                            data: [820, 932, 901, 934, 1290, 1330, 1320],
                            type: 'line',
                            areaStyle: {}
                        }]
                    },

                    option2: {
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [{
                            data: [820, 932, 901, 934, 1290, 1330, 1320],
                            type: 'line',
                            areaStyle: {}
                        }]
                    },
                    lineChart1: {},
                    lineChart2: {},
                    time1: [today, today], // 默认选中 [今天, 今天]
                    time2: [today, today], // 默认选中 [今天, 今天]
                    pickerOptions: {
                        shortcuts: [{
                            text: '昨天',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '今天',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '上个月',
                            onClick(picker) {
                                const now = new Date();

                                // 当前月的第一天
                                const thisMonthFirst = new Date(now.getFullYear(), now.getMonth(), 1);
                                // 上个月的第一天
                                const lastMonthFirst = new Date(now.getFullYear(), now.getMonth() - 1, 1);
                                // 上个月的最后一天 = 当前月第一天 - 1天
                                const lastMonthLast = new Date(thisMonthFirst.getTime() - 24 * 60 * 60 * 1000);

                                picker.$emit('pick', [lastMonthFirst, lastMonthLast]);
                            }
                        }, {
                            text: '最近一周',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '最近一个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '最近三个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                picker.$emit('pick', [start, end]);
                            }
                        }]
                    },
                },
                created() {

                    var that = this

                    setTimeout(function() {
                        that.show_line2('line-chart0')
                        that.show_line('line-chart1')
                        that.show_line('line-chart2')
                    }, 1000);



                },
                methods: {
                    getData() {

                    },
                    show_line(item) {
                        var myChart = Echarts.init(document.getElementById(item), 'walden');

                        // 指定图表的配置项和数据
                        var option = {
                            xAxis: {
                                type: 'category',
                                data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                            },
                            yAxis: {
                                type: 'value'
                            },
                            series: [{
                                data: [49, 92, 61, 134, 90, 130, 120],
                                type: 'line'
                            }]
                        };

                        // 使用刚指定的配置项和数据显示图表。
                        myChart.setOption(option);
                        window.addEventListener('resize', () => {
                            myChart.resize(); // 用箭头函数包装
                        });
                    },
                    show_line2(item) {
                        var myChart = Echarts.init(document.getElementById(item), 'walden');

                        // 指定图表的配置项和数据
                        var option = {

                            tooltip: {
                                trigger: 'item',
                                formatter: '{b}<br/>金额: {c} 元<br/>占比: {d}%'
                            },
                            legend: {
                                top: '2%',
                                left: 'center'
                            },

                            series: [{
                                name: '详细信息',
                                type: 'pie',
                                center: ['50%', '60%'], // 默认是50%高度，往下移到60%
                                label: {
                                    show: true, // 开启标签
                                    position: 'outside', // 默认外侧
                                    formatter: '{b}\n{c}', // 显示名称 + 数值
                                    fontSize: 14
                                },
                                data: [
                                    { value: 1048, name: '利润金额' },
                                    { value: 735, name: '配送金额' },
                                    { value: 580, name: '成本金额' },
                                ],
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }]
                        };

                        // 使用刚指定的配置项和数据显示图表。
                        myChart.setOption(option);
                        window.addEventListener('resize', () => {
                            myChart.resize(); // 用箭头函数包装
                        });
                    },
                    changeMessage() {

                    }
                }
            });
        }
    };

    return Controller;
});